package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC2022 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int[][] construct2DArray(int[] original, int m, int n) {
            if (m * n != original.length) return new int[0][0];
            int[][] res = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    res[i][j] = original[i * n + j];
                }
            }

            return res;
        }
    }

    public void run() {
        Solution solution = new Solution();
//        int[] arr = InputUtil.toIntegerArray("[1,2,3,4]");
//        System.out.println(solution.construct2DArray(arr, 2, 2));

//        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
//        System.out.println(solution.construct2DArray(arr, 1, 3));

        int[] arr = InputUtil.toIntegerArray("[1,2,3,4]");
        System.out.println(solution.construct2DArray(arr, 4, 1));
    }

    public static void main(String[] args) throws Exception {
        LC2022 an = new LC2022();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
